package com.dennytech.tac.model;

import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

import com.dennytech.tac.net.BaseApi;

public class Channel extends CFObject implements Parcelable {

	int id;
	int type;
	String name;
	String intro;
	String photoUrl;

	public Channel() {
	}

	public Channel(Parcel in) {
		id = in.readInt();
		type = in.readInt();
		name = in.readString();
		intro = in.readString();
		photoUrl = in.readString();
	}

	public static Channel decode(JSONObject source) {
		Channel channel = null;
		try {
			channel = new Channel();
			channel.setId(source.getInt("id"));
			channel.setName(source.getString("name"));
			channel.setIntro(source.getString("intro"));

			String photoUrl = source.getString("photourl");
			if (!"".equals(photoUrl)) {
				channel.setPhotoUrl(BaseApi.API_DOMAIN
						+ source.getString("photourl"));
			}

			if (!"".equals(source.getString("ctype"))) {
				channel.setType(Integer.valueOf(source.getString("ctype")));
			}

		} catch (Exception e) {
			return null;
		}

		return channel;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIntro() {
		return intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}

	public String getPhotoUrl() {
		return photoUrl;
	}

	public void setPhotoUrl(String photoUrl) {
		this.photoUrl = photoUrl;
	}
	
	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(id);
		dest.writeInt(type);
		dest.writeString(name);
		dest.writeString(intro);
		dest.writeString(photoUrl);
	}

	public static final Parcelable.Creator<Attraction> CREATOR = new Parcelable.Creator<Attraction>() {
		public Attraction createFromParcel(Parcel in) {
			return new Attraction(in);
		}

		public Attraction[] newArray(int size) {
			return new Attraction[size];
		}
	};

}
